package com.artPreter.controller;


import com.artPreter.pojo.Region;
import com.artPreter.pojo.Result;
import com.artPreter.service.IRegionService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 区域表 前端控制器
 * </p>
 *
 * @author jarvis
 * @since 2024-12-05
 */
@RestController
@RequestMapping("/region")
public class RegionController {

    @Autowired
    private IRegionService regionService;

    /**
     * 区域分页
     * @param currentPage
     * @param size
     * @param
     * @return
     */
    @PostMapping("/getPage")
    public Result getPage(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage, @RequestParam(value = "size",defaultValue = "10") Integer size, @RequestBody Region region) {
        IPage<Region> regionIPage = regionService.getPage(currentPage, size, region);
        return Result.success(regionIPage);
    }

    /**
     *  添加区域
     * @param region
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Region region) {
        regionService.add(region);
        return Result.success();
    }

    /**
     *  修改区域
     * @param region
     * @return
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody Region region) {
        regionService.edit(region);
        return Result.success();
    }

    /**
     * 删除区域
     * @param region
     * @return
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody Region region){
        regionService.delete(region);
        return Result.success();
    }

    /**
     * 获取区域列表
     * @param region
     * @return
     */
    @PostMapping("/getList")
    public Result getList(@RequestBody Region region){
        List<Region> result = regionService.getList(region);
        return Result.success(result);
    }

}
